/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * EditStockJDialog.java
 *
 * Created on 25-Apr-2011, 4:35:28 AM
 */

package shopaddmin;

import digitshoplogic.DBAccessSingleton;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JTextField;

/**
 *
 * @author james
 */
public class EditStockJDialog extends javax.swing.JDialog {

    private Integer UPC;
    private Integer storeId;
    private Integer quantity;

    public JTextField getjTextField1_upc() {
        return jTextField1_upc;
    }

    public void setjTextField1_upc(JTextField jTextField1_upc) {
        this.jTextField1_upc = jTextField1_upc;
    }

    public JTextField getjTextField2_StoreId() {
        return jTextField2_StoreId;
    }

    public void setjTextField2_StoreId(JTextField jTextField2_StoreId) {
        this.jTextField2_StoreId = jTextField2_StoreId;
    }

    public JTextField getjTextField3_quantity() {
        return jTextField3_quantity;
    }

    public void setjTextField3_quantity(JTextField jTextField3_quantity) {
        this.jTextField3_quantity = jTextField3_quantity;
    }



    public Integer getUPC() {
        return UPC;
    }

    public void setUPC(Integer UPC) {
        this.UPC = UPC;
    }

    public Integer getQuantity() {
        return quantity;
    }

    public void setQuantity(Integer quantity) {
        this.quantity = quantity;
    }

    public Integer getStoreId() {
        return storeId;
    }

    public void setStoreId(Integer storeId) {
        this.storeId = storeId;
    }

    /** Creates new form EditStockJDialog */
    public EditStockJDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jTextField1_upc = new javax.swing.JTextField();
        jTextField2_StoreId = new javax.swing.JTextField();
        jTextField3_quantity = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(shopaddmin.ShopAddminApp.class).getContext().getResourceMap(EditStockJDialog.class);
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(52, 68, 109, -1));

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N
        getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(168, 68, -1, -1));

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N
        getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(281, 68, -1, -1));

        jTextField1_upc.setText(resourceMap.getString("jTextField1_upc.text")); // NOI18N
        jTextField1_upc.setEnabled(false);
        jTextField1_upc.setName("jTextField1_upc"); // NOI18N
        getContentPane().add(jTextField1_upc, new org.netbeans.lib.awtextra.AbsoluteConstraints(52, 91, 105, -1));

        jTextField2_StoreId.setText(resourceMap.getString("jTextField2_StoreId.text")); // NOI18N
        jTextField2_StoreId.setEnabled(false);
        jTextField2_StoreId.setName("jTextField2_StoreId"); // NOI18N
        getContentPane().add(jTextField2_StoreId, new org.netbeans.lib.awtextra.AbsoluteConstraints(168, 91, 92, -1));

        jTextField3_quantity.setText(resourceMap.getString("jTextField3_quantity.text")); // NOI18N
        jTextField3_quantity.setName("jTextField3_quantity"); // NOI18N
        getContentPane().add(jTextField3_quantity, new org.netbeans.lib.awtextra.AbsoluteConstraints(281, 91, 87, -1));

        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 160, 95, 54));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        try {
            // TODO add your handling code here:
            String upcStr = jTextField1_upc.getText();
            String storeIdStr = jTextField2_StoreId.getText();
            String quantityStr = jTextField3_quantity.getText();

            String updateStr = "UPDATE stock SET stock.quantity = " + quantityStr
                    + "  where stock.UPC = " + upcStr + " AND "
                    + " stock.storeID = " + storeIdStr;
            
           // System.out.println(updateStr);

            Statement stm = DBAccessSingleton.getInstance().getStatement();
            stm.execute(updateStr);


            
            dispose();
        } catch (SQLException ex) {
            Logger.getLogger(EditStockJDialog.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                EditStockJDialog dialog = new EditStockJDialog(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JTextField jTextField1_upc;
    private javax.swing.JTextField jTextField2_StoreId;
    private javax.swing.JTextField jTextField3_quantity;
    // End of variables declaration//GEN-END:variables

}
